package com.bases {
	import com.skin.SkinManage;
	import flash.display.DisplayObject;
	import flash.display.SimpleButton;
	import flash.display.Sprite;
	import org.bytearray.display.ScaleBitmap;

	public class WindowCloseButton extends TUIComponent {
		private var _closeButton:SimpleButton;

		public function WindowCloseButton(){
			_closeButton = new SimpleButton();
			this.addChild(_closeButton);
			this.addSkin();
		}

		private function buildState(stateStr:String = 'up'):DisplayObject {
			var state:Sprite = new Sprite();
			var bmp:ScaleBitmap;
			switch (stateStr){
				case 'up':
					bmp = new ScaleBitmap(SkinManage.getInstance().getBitmapData('closeBMD'));
					break;
				case 'over':
					bmp = new ScaleBitmap(SkinManage.getInstance().getBitmapData('closeBMD'));
					break;
				case 'down':
					bmp = new ScaleBitmap(SkinManage.getInstance().getBitmapData('closeBMD'));
					break;
				default:
					bmp = new ScaleBitmap(SkinManage.getInstance().getBitmapData('closeBMD'));
					break;
			}
			state.addChild(bmp);
			return state;
		}

		private function addSkin():void {
			this._closeButton.upState = this.buildState('up');
			this._closeButton.downState = this.buildState('down');
			this._closeButton.overState = this.buildState('over');
			this._closeButton.hitTestState = this._closeButton.upState;
		}

		override public function get width():Number {
			return this._closeButton.width;
		}
	}
}